Louie Errors #348

What is wrong with the logic here?

Object o, oSection = section in question
for o in oSection do
{  if (o is in the wrong section)
   {  oDesired = Object of section I want to move this object into
      move(o, last (below(oDesired)))
   }
}


Not shown error checking, such as if oDesired section is locked.

Well, that was about 3 hours today.

-Louie


llandale - Fri Aug 17 17:00:15 EDT 2012

Re: Louie Errors #348
SystemAdmin - Sat Aug 18 04:07:11 EDT 2012

not sure, sounds ok, but did not have the time to check. maybe it is a case of "never iterate over objects which you plan to delete within the loop - use a skip list instead".

Re: Louie Errors #348
llandale - Sat Aug 18 14:57:21 EDT 2012

SystemAdmin - Sat Aug 18 04:07:11 EDT 2012
not sure, sounds ok, but did not have the time to check. maybe it is a case of "never iterate over objects which you plan to delete within the loop - use a skip list instead".

Bingo! When the function found such objects but did not in fact move them, it would find lots that needed moving. But when it actually moved it (to the bottom of the other section), the loop would stop.

So we can reasonable deduce that the various generic:
  • for whatever-2 in whatever-1 do
loops behave like this:
  • Finds the first Whatever-2 inside Whatever-1.
  • deals with loop. Back to top:
  • Find the Whatever-2 that follows the current Whatever-2.

So, since the object is moved to the bottom of the desired section, it HAS no subsequent sibling even though it did before it was moved.

There is another thing that goes on. If within the loop there is another "for obj in o loop" using the same "o" as in the outer loop, it messes up the outer loop. Both of these "features" practically make the following required standard procedure:
  • Skip skpWhatever2 = create()
  • int Sequencer = 0
  • for Whatever-2 in Whatever-1 do
    • put(skpWhatever2, Sequencer++, Whatever-2)
  • for Whatever-2 in skpWhatever2 do
    • bla bla bla
  • delete(skpWhaterver2)

-Louie

Re: Louie Errors #348
SystemAdmin - Sun Aug 19 04:15:28 EDT 2012

llandale - Sat Aug 18 14:57:21 EDT 2012
Bingo! When the function found such objects but did not in fact move them, it would find lots that needed moving. But when it actually moved it (to the bottom of the other section), the loop would stop.

So we can reasonable deduce that the various generic:

  • for whatever-2 in whatever-1 do
loops behave like this:
  • Finds the first Whatever-2 inside Whatever-1.
  • deals with loop. Back to top:
  • Find the Whatever-2 that follows the current Whatever-2.

So, since the object is moved to the bottom of the desired section, it HAS no subsequent sibling even though it did before it was moved.

There is another thing that goes on. If within the loop there is another "for obj in o loop" using the same "o" as in the outer loop, it messes up the outer loop. Both of these "features" practically make the following required standard procedure:
  • Skip skpWhatever2 = create()
  • int Sequencer = 0
  • for Whatever-2 in Whatever-1 do
    • put(skpWhatever2, Sequencer++, Whatever-2)
  • for Whatever-2 in skpWhatever2 do
    • bla bla bla
  • delete(skpWhaterver2)

-Louie

Wow - good explanation, but it did make my brain hurt!


Paul Miller,
Melbourne, Australia